<template>
  <el-drawer v-model="show">
    <el-form :model="props?.row" label-width="80" ref="formRef">
      <el-form-item label="常用语">
        <el-input
          v-model="props.row.chat_text"
          type="textarea"
          :show-word-limit="true"
          :maxlength="500"
          :input-style="{ height: '500px' }"
        ></el-input>
      </el-form-item>
    </el-form>
    <template #footer>
      <el-button type="primary" @click="confirm">确定</el-button>
    </template>
  </el-drawer>
</template>

<script setup lang="ts">
import { FormInstance } from "element-plus";
import { ref } from "vue";
const show = ref(false);

interface Props {
  row: {
    chat_text: string;
  };
  api?: (params: any) => Promise<any>;
  getTable?: () => Promise<any>;
}

const props = ref<Props>({ row: { chat_text: "" } });

const open = (params: any) => {
  props.value = params;
  show.value = true;
};

const formRef = ref<FormInstance>();
const confirm = () => {
  if (!formRef.value) return;
  formRef.value.validate(async valid => {
    if (!valid) return;
    try {
      await props.value.api!(props.value.row);
      await props.value.getTable!();
      show.value = false;
    } catch (error) {}
  });
};

defineExpose({ open });
</script>

<style></style>
